package com.dgshanger.sanhxiaofeisc.ui.person.purse

import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.common.AppApi
import com.dgshanger.sanhxiaofeisc.entity.MemberShipCardEntity
import com.xx.baseuilibrary.adapter.BaseRecycleAdapter
import com.xx.baseuilibrary.adapter.BaseViewHolder
import com.xx.baseuilibrary.mvp.contract.BaseMvpRecycleViewContract
import com.xx.baseuilibrary.mvp.lcec.BaseMvpRecycleViewFragment
import com.xx.baseutilslibrary.network.rx.RxHelper
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver
import kotlinx.android.synthetic.main.item_membership_card_list.view.*


/**
 * MemberShipCardListFragment
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/4/18 15:02.
 */
class MemberShipCardListFragment : BaseMvpRecycleViewFragment<MemberShipCardEntity>() {
    override val listLimit: Int
        get() = 10
    override val layoutManager: RecyclerView.LayoutManager
        get() = LinearLayoutManager(mContext)

    override fun createAdapter(): BaseRecycleAdapter<MemberShipCardEntity, out BaseViewHolder<MemberShipCardEntity>> = Adapter()

    override fun createModel(): BaseMvpRecycleViewContract.Model<MemberShipCardEntity> = Model()


    class Model : BaseMvpRecycleViewContract.Model<MemberShipCardEntity> {
        override fun loadData(page: Int, httpObserver: XxBaseHttpObserver<List<MemberShipCardEntity>>?) {
            AppApi.Api()
                    .my_vip_rcd(page)
                    .compose(RxHelper.io_main())
                    .compose(RxHelper.start_finish(httpObserver))
                    .subscribe(httpObserver)
        }

    }

    class Adapter : BaseRecycleAdapter<MemberShipCardEntity, ViewHolder>() {

        override fun createViewHolder(view: View?, viewType: Int): ViewHolder = ViewHolder(view!!)

        override fun getItemLayout(viewType: Int): Int = R.layout.item_membership_card_list

    }

    class ViewHolder(view: View) : BaseViewHolder<MemberShipCardEntity>(view) {
        override fun bindView(position: Int, entity: MemberShipCardEntity?) {
            with(entity!!) {
                itemView.tv_leaving_return_time.text = leaving_return_time
                itemView.tv_return_time.text = return_time
                itemView.tv_created_at.text = created_at

                itemView.tv_leavings_integral.text = leavings_integral
                itemView.tv_present_integral.text = present_integral

                itemView.tv_leavings_wallet_money.text = leavings_wallet_money
                itemView.tv_present_wallet_money.text = present_wallet_money
                
                itemView.tv_vip_name.text = vip_name
            }
        }
    }

}